<!-- A.vue -->
<template>
  <div>
    <button @click="handleClick">触发事件</button>
    <Bcom></Bcom>
    <Bcom></Bcom>
  </div>
</template>
<script>
import Emitter from '../mixins/emitter.js';
import Bcom from '@/views/B.vue'
import { findComponentDownward } from '@/utils/assist.js';
export default {
  name: 'componentA',
  components: {
    Bcom
  },
  mixins: [Emitter],
  data() {
    return {
      name: 'Aresn'
    }
  },
  created() {
    this.$on('on-messageA', this.showMessage);
  },
  mounted() {
    const comB = findComponentDownward(this, 'componentB')
    if (comB) {
      console.log('找到了')
    }
  },
  methods: {
    handleClick() {
      this.broadcast('componentB', 'on-message', 'Hello Vue.js');
    },
    showMessage(text) {
      window.alert(text);
    },
    sayHello() {
      alert('sayHello')
    }
  }
}
</script>